#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2019/11/21 14:09|14:09
# @Author  : yangdingyi
# @File    : 移除元素
# @Software: PyCharm
from typing import List


class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        i, j, n = 0, 0, len(nums)
        while j < n:
            while i < n and nums[i] != val:
                i += 1
            if i < j < n and nums[j] != val:
                nums[i], nums[j] = nums[j], val
                j += 1
                i += 1
            else:
                j += 1
        return i


solve = Solution()
nums = [3, 2, 2, 3]
print(nums)
print(solve.removeElement(nums, 2))
print(nums)
